package wxapp

import (
    "fmt"
	"wxsdk/miniapp/core"
	"github.com/astaxie/beego"
)

// 数据分析接口
type DataAnalysisRequest struct {
	ReqUrl     string `json:"-"`
	BeginDate  string `json:"begin_date"`
	EndDate    string `json:"end_date"`
}

func (r *DataAnalysisRequest) GetApiMethodName(token string) string {
	return fmt.Sprintf("%s?access_token=%s",r.ReqUrl, token)
}

func  GetDataAnalysis(reqUrl,beginDate,endDate,authorizerAccessToken string) (string, error){
	client := core.GetPostJSONClient()
	var req = new(DataAnalysisRequest)
	req.ReqUrl = reqUrl
	req.BeginDate = beginDate
	req.EndDate = endDate
	serverUrl := req.GetApiMethodName(authorizerAccessToken)
	tbdata, err := client.Excute("POST", serverUrl, req, nil)
	if err != nil {
		beego.Critical(err.Error())
		return "", err
	}
	return string(tbdata), nil
}
